package cn.itsource.pethome.user.mapper;

import cn.hutool.core.collection.CollectionUtil;
import cn.itsource.pethome.base.superr.MyBaseMapper;
import cn.itsource.pethome.user.domain.User;

import java.util.List;
import java.util.Objects;

/**
 * @author: hong
 * @Description:
 * @Date: Created in 12:54 2022/2/25
 * @Modified: By:
 */
public interface UserMapper extends MyBaseMapper<User> {

    /**
     * 重写获取泛型的class方法
     * @return
     */
    @Override
    default Class<User> getTClass () {
        return User.class;
    }

    default boolean findPhoneExist (String phone){
        if(Objects.nonNull (this.findUserByPhone (phone))){
            return Boolean.TRUE;
        }else {
            return Boolean.FALSE;
        }
    };

    default User findUserByPhone (String phone){
        User user = new User ();
        user.setPhone (phone);
        List<User> select = this.select (user);
        if(CollectionUtil.isEmpty (select)){
            return null;
        }else{
            return select.get (0);
        }
    };
}
